package com.qmyx.supplychain.quartz.task;

import com.ytjj.qmyx.supplychain.service.ReconciliationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class ReconciliationTask {

    @Resource
    private ReconciliationService reconciliationService;

    /**
     * 日结 每天晚上0:00:00 运行一次 (前一天的 0:00:00 - 23:59:59)
     */
    @Scheduled(cron = "0 0 0 * * ?")
    public void verifyReconciliationByDay(){
        log.info("==============开始计算日结账单==================");
        reconciliationService.verifyReconciliationByDay(null);
        log.info("==============结束计算日结账单==================");
    }

    /**
     * 周结 周一晚上00:00:00 运行一次 (上周星期一的 0:00:00 - 上周星期天23:59:59)
     */
    @Scheduled(cron = "0 0 0 ? * MON")
    public void verifyReconciliationByWeek(){
        log.info("==============开始计算周结账单==================");
        reconciliationService.verifyReconciliationByWeek();
        log.info("==============结束计算周结账单==================");
    }

    /**
     * 月结 1号晚上00:00:00 运行一次 (上个月的1号00:00:00 - 上个月的最后一天的23:59:59)
     */
    @Scheduled(cron = "0 0 0 1 * ?")
    public void verifyReconciliationByMonth(){
        log.info("==============开始计算月结账单==================");
        reconciliationService.verifyReconciliationByMonth();
        log.info("==============结束计算月结账单==================");
    }

    /**
     * 半月结 16号晚上00:00:00 运行一次 (这个月的1号00:00:00 - 15号23:59:59)
     */
    @Scheduled(cron = "0 0 0 16 * ?")
    public void verifyReconciliationByFirstMonth(){
        log.info("==============开始计算上半月结账单==================");
        reconciliationService.verifyReconciliationByFirstMonth();
        log.info("==============结束计算上半月结账单==================");
    }

    /**
     * 半月结 1号晚上00:00:00 运行一次 (上个月的16号00:00:00 - 上个月的最后一天的23:59:59)
     */
    @Scheduled(cron = "0 0 0 1 * ?")
    public void verifyReconciliationBySecondMonth(){
        log.info("==============开始计算下半月结账单==================");
        reconciliationService.verifyReconciliationBySecondMonth();
        log.info("==============结束计算下半月结账单==================");
    }
}
